import axios from "axios"; //引入axios

import nprogress from "nprogress"; //引入进度条
import "nprogress/nprogress.css"; //引入进度条样式



const request=axios.create(
    {
        timeout:5000,
    })

request.interceptors.request.use(  //请求拦截器
     config=>{
        nprogress.start();        //进度条开始
        config.headers['Content-Type'] = 'application/json;charset=utf-8';
        if (localStorage.getItem('token')) {       
            config.headers['token'] = localStorage.getItem("token");        
        }
  
        return config;
    });

request.interceptors.response.use( //响应拦截器
    res=>{   
        nprogress.done();         //进度条结束
        return res
    })

export default request;